<?php

	// Todo: Move to the public branch?

	if (!defined('FRAMEWORK_INIT'))
	{
		die('How come FRAMEWORK_INIT not be initalized when it should? Try index.php?action=register !');	
	}
	header('Content-Type: text/plain');

	$product = $_GET['product'];
	$version = $_GET['version'];
	$installer = $_GET['installer'];
	$username = $_GET['username'];
	$password = $_GET['password'];
	$function = $_GET['function'];
	$parameter = $_GET['parameter'];
	
	if ( !isset($username) || $username == "")
	{
		die('Error "The Username recieved by the content servers was invalid or missing."');
	}
	if ( !isset($version) || $version == "")
	{
		die('Error "The version requested was invalid or missing."');
	}
	if ( !isset($product) || $product == "")
	{
		die('Error "The product requested was invalid or missing."');
	}
	
	if (!file_exists('scripts/'.$product.'.php'))
	{
		die( 'error "The product requested ('.$product.') is not supported by this content server at the moment."' );
	}
	

	include('scripts/'.$product.'.php');
	
	if ( strcmp($function,"progress") == 0 )
	{
		
		$arraysize = count($progress_id_to_value[$product]);
		
		$progress = -1;
		
		for ($i = 0; $i < $arraysize; $i++)
		{
			if ( strcasecmp($progress_id_to_value[$product][$i],$parameter) == 0 )
			{
				$progress = $i;
			}		
		}
		
		if ($progress == -1)
		{
			die('error "This content server did not recognize the map '.$parameter.'"');
		}
			
		if (!is_int($progress))
		{
			$progress	=	-1;	// Error		
		}
		
		$register_query = sprintf("UPDATE distribution_register SET progress = %s WHERE username = %s AND product = %s AND progress < %s ORDER BY id ASC",
		slash($progress),
		slash($username),
		slash($product),
		slash($progress));
		
		sql_once($register_query);
		
		echo 'OK';
	}
	else
	{
		die('error "The function '.$function.' with parameter '.$parameter.' is not supported by this content server."');
	}
?>